$(function () {
    obj.init();
});
var dataTest = [
    {
        start: '2019-02-18 18:30:00',
        end: '2019-02-18 21:20:00',
        title: '会议1'
    }
];
var currentDate = '';
var obj = new function () {
    'use strict';
    return {
        form:null,
        calendar:null,
        holidayArr:[],
        init:function () {
            this.calendar = $('#calendar');
            currentDate = new Date().format("yyyy-MM-dd");
            this.funObj().renderSchedule();
            this.listener();
        },
        listener:function () {
            var $this = this;
            
            // $('[name=room]').change(function () {
            //     $this.funObj().changeRoom();
            // });

            $('#topBar a').click(function () {  //左侧工具栏点击事件
                $('#topBar a').each(function () {
                    $(this).find('input').removeAttr("checked");
                    var attr = $(this).attr('style');
                    if($(this).hasClass('modal-btn-checked')){
                        $(this).removeClass('modal-btn-checked');
                    }
                });
                $(this).find('input').attr('checked','checked').prop("checked",'checked');
                $(this).addClass('modal-btn-checked');
                $this.funObj().changeRoom();
            });
            // $('#topBar a').eq(0).click();

        },
        funObj:function () {
            var $this = this;
            return {
                renderSchedule:function () {
                    $this.calendar.fullCalendar('destroy');
                    $this.calendar.fullCalendar({
                        header: {
                            left: 'prev,room,next',
                            center: 'title',
                            right: 'agendaWeek'
                        },
                        allDaySlot: false,//不显示全天
                        height : window.innerHeight-30,
                        windowResize: function(view) {
                            $this.calendar.fullCalendar('option', 'height', window.innerHeight-26);
                            $this.calendar.fullCalendar('option', 'width', 800);
                        },
                        defaultView: 'agendaWeek',
                        navLinks: false, // can click day/week names to navigate views
                        locale:'zh-cn',
                        defaultDate: currentDate,
                        slotLabelFormat:'HH:mm',
                        slotDuration:'00:15:00',
                        timeFormat: 'HH:mm',
                        minTime:'09:00:00',
                        eventLimit: false, // allow "more" link when too many events
                        eventClick: function(event, jsEvent, view) {

                        },
                        events: function (start, end, timezone, callback) {
                            $this.calendar.focus();
                            xhExtra.ajaxRequest('lm/meeting/getCalendar',{startDay:start.format(),endDay:end.format(),room:$('[name=room]:checked').val()},{},function (res) {
                                callback.call(this, res);
                            });
                        },
                        eventMouseover: function(event, jsEvent, view){
                            $(this).attr("title","<b style='font-size: large'>"+event['extraData']['sTitle']+"</b>")
                                .attr("data-container","body")
                                .attr ("data-toggle","popover")
                                .attr("data-content","<p style='font-size: medium'>" +
                                        "申请人:"+event['extraData']['sApplyName']+"("+event['extraData']['sPhone']+")<br>"+
                                        "开始时间:"+event['extraData']['tStartTime']+"<br>"+
                                        "结束时间:"+event['extraData']['tEndTime']+"<br>"+
                                    "</p>")
                                .attr("data-html","true")
                                .attr("data-trigger","hover")
                                .attr("data-placement","bottom");

                            $("[data-toggle='popover']").popover();
                        }
                    });

                },
                changeRoom:function () {
                    $this.calendar.fullCalendar('refetchEvents');
                }
            }
        }
    }
};

Date.prototype.format =function(format)
{
    var o = {
        "M+" : this.getMonth()+1, //month
        "d+" : this.getDate(), //day
        "h+" : this.getHours(), //hour
        "m+" : this.getMinutes(), //minute
        "s+" : this.getSeconds(), //second
        "q+" : Math.floor((this.getMonth()+3)/3), //quarter
        "S" : this.getMilliseconds() //millisecond
    }
    if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
        (this.getFullYear()+"").substr(4- RegExp.$1.length));
    for(var k in o)if(new RegExp("("+ k +")").test(format))
        format = format.replace(RegExp.$1,
            RegExp.$1.length==1? o[k] :
                ("00"+ o[k]).substr((""+ o[k]).length));
    return format;
}